//
//  HXDHome.swift
//  weibo
//
//  Created by huxuedong on 15/12/9.
//  Copyright © 2015年 huxuedong. All rights reserved.
//

import UIKit

class HXDStatus: NSObject {
    
    //内容
    var text: String?
    //作者
    var user: HXDUser?
    //发送时间
    var created_at: String?
    //来源
    var source: String?
    //转发
    var reposts_count: Int = 0
    //评论数
    var comments_count: Int = 0
    //点赞数
    var attitudes_count: Int = 0
    //转发微博的内容
    var retweeted_status: HXDStatus?
    //转发微博的配图
    var pic_urls: [HXDRetweetedPicture]?
    //每条微博的id
    var id: Int64 = 0
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) { }
    
    //重写setValueforkey
    override func setValue(value: AnyObject?, forKey key: String) {
        //当key为user时，判断此时value是否为字典，再调用初始化方法赋值
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                user = HXDUser(dict: dict)
            }
            //当key为retweeted_status时，判断此时value是否为字典，再调用初始化方法赋值
        } else if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = HXDStatus(dict: dict)
            }
            //当key为pic_urls时，判断此时value是否为字典，再调用初始化方法赋值
        } else if key == "pic_urls" {
            if let array = value as? [[String: AnyObject]] {
                var tempArray = [HXDRetweetedPicture]()
                for dict in array {
                    tempArray.append(HXDRetweetedPicture(dict: dict))
                }
                pic_urls = tempArray
            }
        } else {
            super.setValue(value, forKey: key)
        }
    }
    
    override var description: String {
        let keys = ["text", "retweeted_status"]
        return dictionaryWithValuesForKeys(keys).description
    }

}
